package com.kelp.codetoolkit.renderer

import com.intellij.ui.JBColor
import com.kelp.codetoolkit.data.SpringConfigListItem
import java.awt.*
import javax.swing.*

/**
 * @author: liuyuebai
 * @date: 2025/9/10 14:01
 * @description:
 */
class SpringConfigListCellRenderer: ListCellRenderer<SpringConfigListItem> {


    override fun getListCellRendererComponent(
        list: JList<out SpringConfigListItem?>,
        value: SpringConfigListItem,
        index: Int,
        isSelected: Boolean,
        cellHasFocus: Boolean
    ): Component {
        // 先获取原有逻辑处理的label（包含文字）
        val label = DefaultListCellRenderer().getListCellRendererComponent(list, value, index, isSelected, cellHasFocus) as JLabel
        // 创建包含label和checkBox的面板，使文字和复选框共存
        val panel = JPanel(BorderLayout())
        panel.add(label, BorderLayout.CENTER)
        // === 关键逻辑：根据 valueObj 类型决定是否添加 JTextField ===
        val obj = value.valueObj
        if (obj !is Map<*, *> || obj !is List<*>) {
            val textField = JTextField(obj.toString())
            textField.isEditable = false   // 如果只是展示，可以禁用编辑
            panel.add(textField, BorderLayout.SOUTH)
        }
        panel.background = label.background
        return panel
    }
}